<template>
  <el-card class="base-info-card">
    <div v-if="child.times > 1">
      <div class="top">
        <div>身高：{{ child.height || '无' }}</div>
        <div>体重：{{ child.weight || '无' }}</div>
        <div>体质：{{ child.body_name || '无' }}</div>
      </div>
      <div class="bottom">
        <div>
          第<span class="blue">{{ child.times }}</span
          >次咨询
        </div>
        <div>
          上次结果：<span
            class="blue"
            style="cursor:pointer"
            @click="showDialog = true"
            >{{ child.symptoms_name || '无' }}</span
          >
        </div>
        <div style="position:absolute;right:20px">
          上次咨询时间：{{ child.last_time || '无' }}
        </div>
      </div>
      <el-button
        round
        class="look-change"
        type="primary"
        icon="el-icon-search"
        @click="showList = true"
        >查看症状变化</el-button
      >
    </div>
    <div v-else class="blue big-blue">
      首次咨询
    </div>
    <babyDialog :show.sync="showList">
      <div class="dailog-container fuck-container-go" style="background:#fff">
        <div
          v-for="(item, index) in list"
          :key="index"
          class="fuck-column"
          :style="{width: `${140 * list[0].length}px`}"
        >
          <template v-for="(it, i) in item">
            <div
              v-if="i === 1 && it.id"
              :key="i"
              :title="it.name"
              class="item item-record"
              @click="showRecordDialog(it.id)"
            >
              {{ it.name }}
            </div>
            <div
              v-else-if="i === 1 && !it.id"
              :key="i"
              class="item"
              :title="it.name"
            >
              {{ it.name }}
            </div>
            <div v-else :key="i" class="item" :title="it">
              {{ it }}
            </div>
          </template>
        </div>
      </div>
    </babyDialog>
    <babyDialog :show.sync="showDialog">
      <div class="dailog-container">
        <detailBase :user="user" :result="result"></detailBase>
        <solution
          :hand-list="handList"
          :hand-list-simple="handListSimple"
          :say-list="sayList"
          :food-list="foodList"
          :food-book="foodBook"
          :progress="progress"
        ></solution>
      </div>
    </babyDialog>
  </el-card>
</template>
<script>
import babyDialog from '@/components/common/babyDialog/babyDialog';
import detailBase from '@/components/advisory/advisoryDetail/detailBase';
import solution from '@/components/advisory/advisoryDetail/solution';

export default {
  components: {
    babyDialog,
    detailBase,
    solution
  },
  props: {
    child: [Object]
  },
  data() {
    return {
      showDialog: false,
      showList: false,
      user: {},
      result: {},
      product: [],
      doctors: [],
      recommendProductId: [],
      progress: {
        book: [],
        medicine: [],
        nutrition: [],
        physical: [],
        stick: [],
        fit_tuina: '',
        bubble: []
      },
      handList: {list: []},
      handListSimple: {list: []},
      sayList: {},
      foodBook: [],
      foodList: {},
      commodity: [],
      list: []
    };
  },
  watch: {
    child(v) {
      if (v.times > 0 && v.record_id) {
        this.getRecord(v.record_id);
        this.getRecordList();
      }
    }
  },
  methods: {
    getRecord(record_id) {
      return this.$http
        .post(this.$url.getRecord, {
          u_id: this.child.id,
          record_id,
          is_medical: 2
        })
        .then(res => {
          this.user = res.user;
          this.result = res.result;
          this.progress = res.progress;
          this.handList = res.handList;
          this.handListSimple = res.handListSimple;
          this.sayList = res.sayList;
          this.foodList = res.foodList;
          this.foodBook = res.foodBook;
          this.commodity = res.commodity;
        })
        .catch(this.$catch);
    },
    getRecordList() {
      this.$http
        .post(this.$url.getChangeRecord, {
          u_id: this.child.id
        })
        .then(res => {
          const arr = [
            ['类别', {name: '咨询结果', id: 0}, '舌苔'].concat(
              res.title.map(it => it.phenomenon_name)
            )
          ];
          res.content.forEach(it => {
            arr.push(
              [
                it.from,
                {name: it.symptoms, id: it.record_id},
                it.tongue
              ].concat(it.symptom)
            );
          });
          this.list = arr;
        })
        .catch(this.$catch);
    },
    showRecordDialog(record_id) {
      this.getRecord(record_id).then(() => {
        this.showDialog = true;
      });
    }
  }
};
</script>
<style lang="scss" scoped>
.base-info-card {
  position: relative;
}
.top,
.bottom {
  display: flex;
  font-size: 16px;
  color: #333;
  box-sizing: border-box;
  div {
    min-width: 220px;
  }
}
.bottom {
  margin-top: 48px;
  padding-bottom: 10px;
}
.blue {
  margin: 0 10px;
  font-size: 20px;
  color: #4b90ff;
}
.big-blue {
  line-height: 100px;
  height: 100px;
}
.look-change {
  position: absolute;
  right: 30px;
  top: 10px;
  //   transform: translateY(-50%);
  background-color: #4b90ff;
  color: #fff;
  // font-size: 16px;
  // font-weight: bold;
}
.fuck-container-go {
  padding-top: 40px;
  overflow: scroll;
  max-height: 500px;
}
.fuck-column {
  //   display: flex;
  font-size: 16px;
  white-space: nowrap;
  .item {
    display: inline-block;
    padding: 20px;
    width: 100px;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: center;
    color: #847a7a;
    &.item-record {
      cursor: pointer;
      &:hover {
        color: #4b90ff;
      }
    }
  }
  &:first-child {
    font-weight: bold;
    .item {
      color: #333;
    }
  }
  &:nth-child(2n + 1) {
    background: #f7f8fd;
  }
}
</style>
